
Ext.namespace("Ext.milan.pagejs.page_officeItemsCollar");
Ext.milan.pagejs.page_officeItemsCollar.userWin = null;
Ext.milan.pagejs.page_officeItemsCollar.subWin = null;
Ext.milan.pagejs.page_officeItemsCollar.REQUEST_ACTION = "officeItemsCollar";
var selectPostionTree = null;
Ext.milan.pagejs.page_officeItemsCollar.docLoadBeforeCallBack = function() {
};

Ext.milan.pagejs.page_officeItemsCollar.docOnReadyCallback = function() {

};

/**
 * 关闭子弹出窗口
 */
Ext.milan.pagejs.page_officeItemsCollar.closeSubWin = function() {
	Milan.commonutils.closeModelPop(Ext.milan.pagejs.page_officeItemsCollar.subWin);
};

/**
 * 关闭弹出窗口
 */
Ext.milan.pagejs.page_officeItemsCollar.closeWin = function(winName) {
	if(winName){
		if(winName=='inactivateConsignerWin')
			inactivateConsignerWin.closeDialog();
	}
	else
		Milan.commonutils.closeModelPop(Ext.milan.pagejs.page_officeItemsCollar.userWin);
};

/*------------------------ private methods -----------------------*/

/**
 * 查询所有
 */
Ext.milan.pagejs.page_officeItemsCollar._search = function() {
	Ext.milan.pagejs.common_utils.query(false, "officeItemsCollar/list.do");
};

Ext.milan.pagejs.page_officeItemsCollar._formCheck = function(frm) {
	function focusElement(el) {
		if(el.focus)
			el.focus();
	};
	if(frm.wpid.value.trim() == "") {
		Milan.commonutils.createDelayNotifyModel("提示信息", "物品 不能为空！");
		return false;
	}
	if(frm.lyrmc.value.trim() == "") {
		Milan.commonutils.createDelayNotifyModel("提示信息", "领用人 不能为空！");
		return false;
	}
	if(frm.lyrq.value.trim() == "") {
		Milan.commonutils.createDelayNotifyModel("提示信息", "领用日期 不能为空！");
		return false;
	}
	if(frm.sl.value.trim() == "") {
		Milan.commonutils.createDelayNotifyModel("提示信息", "数量 不能为空！");
		return false;
	}
	if(frm.ffrmc.value.trim() == "") {
		Milan.commonutils.createDelayNotifyModel("提示信息", "发放人 不能为空！");
		return false;
	}
	if(frm.deptname.value.trim() == "") {
		Milan.commonutils.createDelayNotifyModel("提示信息", "领用部门 不能为空！");
		return false;
	}
	return true;
};

/**
 * 保存信息
 */
Ext.milan.pagejs.page_officeItemsCollar._saveInfo = function(formId) {
	if(!Ext.milan.pagejs.page_officeItemsCollar._formCheck($(formId)))
		return;
		
	Milan.ajaxutility.formSubmit({
		form:formId,
		success:function(response)
		{
			Ext.milan.pagejs.page_officeItemsCollar.closeWin();
			Ext.milan.pagejs.page_officeItemsCollar.query();
		}
	});
};

/**
 * 条件查询列表
 */
Ext.milan.pagejs.page_officeItemsCollar.query = function() {
	Milan.pagejs.page_index.updateCurrentTabByForm("query_officeItemsCollar_list_form");
};

/**
 * 显示新建表单
 */
Ext.milan.pagejs.page_officeItemsCollar.showAddForm = function() {
	var url = Ext.milan.pagejs.page_officeItemsCollar.REQUEST_ACTION + "/create.do";
	Ext.milan.pagejs.page_officeItemsCollar.userWin = Milan.commonutils.createModelPop({
		title:"新建", 
		url:url,
		width:650
	});
};

/**
 * 显示编辑表单
 * 
 * @param ID
 */
Ext.milan.pagejs.page_officeItemsCollar.showEditForm = function(id) {
	var url = Ext.milan.pagejs.page_officeItemsCollar.REQUEST_ACTION + "/edit.do?id=" + id;
	Ext.milan.pagejs.page_officeItemsCollar.userWin = Milan.commonutils.createModelPop({
		title:"编辑",
		url:url,
		width:650
	});
};

/**
 * 保存新建用户信息
 */
Ext.milan.pagejs.page_officeItemsCollar.save = function(formId) {
	Ext.milan.pagejs.page_officeItemsCollar._saveInfo(formId);
};

/**
 * 保存编辑后的信息
 */
Ext.milan.pagejs.page_officeItemsCollar.edit = function(formId) {
	Ext.milan.pagejs.page_officeItemsCollar._saveInfo(formId);
};

Ext.milan.pagejs.page_officeItemsCollar.deleteForm = function(id) {
	var url = Ext.milan.pagejs.page_officeItemsCollar.REQUEST_ACTION + "/delete.do?id=" + id;
	new Milan.widget.ConfirmDialog("确认信息", "确认要删除该信息吗？", {
		confirmCallback: function() {
			Milan.ajaxutility.formSubmit({
				url: url,
				method: 'post',
				success: function(response, option)
				{
					Ext.milan.pagejs.page_officeItemsCollar.query();
				}
			});
		}
	});	
};

/**
 * 查看详情
 * 
 * @param entityId 用户ID
 */
Ext.milan.pagejs.page_officeItemsCollar.viewDetail = function(entityId) {
	var url = Ext.milan.pagejs.page_officeItemsCollar.REQUEST_ACTION + "/show.do?id=" + entityId;
	Ext.milan.pagejs.page_officeItemsCollar.userWin = Milan.commonutils.createModelPop({
		title:"详细信息",
		url:url,
		width:500
	});
};

Ext.milan.pagejs.page_officeItemsCollar.selectUsers = function(selectItemId) {

	new Milan.widget.Selector({
		orgType:"12",
		title:"选择分组人员",
		deptUrl:"dept/selectDept.do?",
		quickSelectUrl:"user/quickUser.do?",
		searchUrl:"user/searchUser.do?",
		isRecentEnable :false,
		isUpdateRecentEnable :false,
		isDeptSelEnable:false
	},
	false,
	{
		onSelectedCallBack : function(arr)
		{
			var selectItem = $(selectItemId);
			var isExisted = false;
			if(arr != null && arr.length > 0) {
				for (var i = 0; i<arr.length; i++) {
					for (var x = 0; x < selectItem.length; x++) {
						if (arr[i].id == selectItem[x].value) {
							isExisted=true;
							break;
						}	
					}
					
					if (!isExisted) {
						//document.getElementById('_wp_user_of_add_wf').innerHTML = arr[i].name;
						$('lyrmc').value = arr[i].name;
						$('lyrid').value = arr[i].id;
					}
						
					isExisted = false;
				}
			}  
		}
	});
};

